Code
library(tidyverse)
library(openxlsx)
library(readxl)input and output data to csv;excel ect
Tony Duan
July 5, 2023

read_csv()write.csvread_excel()write.xlsxexcel file link:
find sheet names
read_sheet()---
title: "R Data input and output"
subtitle: "input and output data to csv;excel ect"
author: "Tony Duan"
date: "2023-07-05"
categories: [R]
execute:
eval: false
warning: false
error: false
format:
html:
toc: true
code-fold: show
code-tools: true
number-sections: true
code-block-bg: true
code-block-border-left: "#31BAE9"
---

```{r}
library(tidyverse)
library(openxlsx)
library(readxl)
```
## CSV
```{r}
#| echo: false
#| eval: false
# create csv and excel
data001=mtcars
write.csv(data001,'data001 csv data.csv')
write.xlsx(data001,'data001 excel data.xlsx')
```
### input with `read_csv()`
```{r}
data001=read_csv('data001 csv data.csv')
head(data001)
```
### output with `write.csv`
```{r}
write.csv(data001,'data001 csv output data.csv')
```
## EXCEL
### input with `read_excel()`
```{r}
data001=read_excel('data001 excel data.xlsx')
head(data001)
```
### output with `write.xlsx`
```{r}
write.xlsx(data001,'data001 excel output data.xlsx')
```
## Read from googlesheet
```{r}
library(googlesheets4)
```
excel file link:
```{r}
link='https://docs.google.com/spreadsheets/d/14_suWY8fCPEXV0MH7ZQMZ-KndzMVsSsA5HdR-7WqAC0'
```
find sheet names
```{r}
sheet_names(link)
```
### read excel by sheet names with `read_sheet()`
```{r}
aa=read_sheet(link,"data-for-countries-etc-by-year")
```
```{r}
head(aa)
```
## using pins pacakge
## Reference